package com.lu.derby.controller;

import com.lu.derby.model.SysUser;
import com.lu.derby.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program derby-demo
 * @description:
 * @author: zhanglu
 * @create: 2020-06-16 17:13:00
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/get/{id}")
    public Object get(@PathVariable String id){
        SysUser sysUser = sysUserService.getById(id);
        return sysUser;
    }

    @GetMapping("/list")
    public Object getList(){
        return sysUserService.list();
    }

    @GetMapping("/insert")
    public boolean insert(String id, String name, Integer age){
        SysUser sysUser = new SysUser();
        sysUser.setId(id).setName(name).setAge(age);
        return sysUserService.save(sysUser);
    }

    @GetMapping("/update")
    public boolean update(String id, String name, Integer age){
        SysUser sysUser = new SysUser();
        sysUser.setId(id).setName(name).setAge(age);
        return sysUserService.updateById(sysUser);
    }

    @GetMapping("/delete/{id}")
    public boolean delete(@PathVariable String id){
        return sysUserService.removeById(id);
    }

}



